#!/bin/bash

if [ $# -ne 2 ];then
    echo "Usage: $0 path service"
    exit 1
fi

path=$1
service=$2

tmp=`systemctl`
if [ $? -ne 0 ];then
    mkdir -p $path/etc/rc.d/init.d
    touch $path/etc/rc.d/init.d/$service
    sed "s/{service}/$service/g" service.init > $path/etc/rc.d/init.d/$service
    chmod a+x $path/etc/rc.d/init.d/$service
else
    mkdir -p $path/usr/lib/systemd/system
    touch $path/usr/lib/systemd/system/$service.service
    sed "s/{service}/$service/g" service.systemd > $path/usr/lib/systemd/system/$service.service
    chmod a+x $path/usr/lib/systemd/system/$service.service
fi
